<template>
	<div class="content">
		<div class="clear">
			<Form inline class="fl">
				<Input type="text" placeholder="UUID" class="w200 m-r10" v-model.trim="uuid" />
				<Input type="text" placeholder="手机号码" class="w200 m-r10" v-model.trim="phone" />
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="ifGetQuery">查询</Button>
			</Form>
		</div>
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon> 导出</Button>
		<Table stripe :columns="columns" ref="table" :data='list' :loading="loading"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				dcShow: false,
				loading: true,
				jsonData: [],
				list: [], // 分享收益列表数据
				num: '', // 累计分享收益
				info: null, // 总条数
				page: 1, // 页数
				pageSize: 20, // 每页多少条
				current: 1,
				phoneEmail: '',
				downList: [],
				dataValue: ['',''], // 时间段值
				uuid: '', // 用户 ID
				phone: '', // 手机号码
				list2: [],
				columns: [{
						title: '认证者UUID',
						align: 'center',
						key: 'uuid',
						render: (h, params) => {
							return h('div', params.row.uuid == null ? '#' : params.row.uuid)
						}
					},
					{
						title: '认证者手机号码',
						align: 'center',
						key: 'phone',
						render: (h, params) => {
							return h('div', params.row.phone == null ? '#' : params.row.phone)
						}
					},
					{
						title: '认证者姓名',
						align: 'center',
						key: 'trueName',
						render: (h, params) => {
							return h('div', params.row.trueName == null ? '暂未推荐实名用户' : params.row.trueName)
						}
					},
					{
						title: '认证者身份证',
						align: 'center',
						key: 'idCard',
						render: (h, params) => {
							return h(
								'div', params.row.idCard == null ? '#' : params.row.idCard
							)
						}
					},
					{
						title: '所属代数',
						align: 'center',
						key: 'nodeNumber',
						render: (h, params) => {
							return h(
								'div', params.row.nodeNumber == null ? '#' : params.row.nodeNumber
							)
						}
					},
					{
						title: '赠送数量',
						align: 'center',
						key: 'num',
						render: (h, params) => {
							return h(
								'div', params.row.num == null ? '#' : this.Fixed(params.row.num)
							)
						}
					},
					{
						title: '赠送时间',
						align: 'center',
						key: 'createTime',
						sortable: true,
						render: (h, params) => {
							return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
						}
					}
				],
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			})
			this.getQuery() // 查询直推奖励
		},
		methods: {
			exportData() {
				this.jsonData = [];
				this.dcShow = true;
				this.axios.post('/admin/statistical/integral/giving/getCandy', this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.uuid,
					phone: this.phone,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.axios.post('/admin/statistical/integral/giving/getCandy', this.qs.stringify({
							current: 1, // 当前页【可选，默认1】
							size: res.data.data.total, // 每页记录数【可选，默认20】
							uuid: this.uuid,
							phone: this.phone,
							startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
							endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
						})).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.downList[index].createTime = this.downList[index].createTime;
									this.downList[index].uuid = this.downList[index].uuid;
									this.downList[index].phone = this.downList[index].phone;
									this.downList[index].trueName = this.downList[index].trueName;
									this.downList[index].idCard = this.downList[index].idCard;
									this.downList[index].nodeNumber = this.downList[index].nodeNumber;
									this.downList[index].num = this.Fixed(this.downList[index].num);
									this.jsonData.push({
										uuid: this.downList[index].uuid,
										phone: this.downList[index].phone,
										trueName: this.downList[index].trueName,
										idCard: this.downList[index].idCard,
										nodeNumber: this.downList[index].nodeNumber,
										num: this.downList[index].num,
										createTime: this.downList[index].createTime,
									})
								})
								let str = `认证者UUID,认证者手机号码,认证者姓名,认证者身份证,所属代数,赠送数量,赠送时间\n`;
								this.downLoad(this.jsonData, str, '糖果赠送');
							}
						})
					}
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange
			},
			getQuery() {
				this.loading = true;
				this.axios.post('/admin/statistical/integral/giving/getCandy', this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.uuid,
					phone: this.phone,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			cuctGetQuery(page) { // 分页查询直推奖励
				this.loading = true;
				this.axios.post('/admin/statistical/integral/giving/getCandy', this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.uuid,
					phone: this.phone,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			},
			ifGetQuery() { // 条件查询直推奖励
				this.page = 1;
				this.loading = true;
				this.axios.post('/admin/statistical/integral/giving/getCandy', this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.uuid,
					phone: this.phone,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.info = res.data.data.total;
						this.loading = false;
					}
				})
			}
		}
	}
</script>